﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Basic.Model.Entity;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Criterion;

namespace Basic.Model.EntityManager
{
    public class MenuNodeManager
    {
        public static void Add(ISession session, MenuNode an)
        {
            session.Save(an);
        }

        public static void Delete(ISession session, MenuNode an)
        {
            session.Delete(an);
        }

        public static void Update(ISession session, MenuNode an)
        {
            session.Update(an);
        }

        public static MenuNode Get(ISession session, int itemId)
        {
            return session.Get<MenuNode>(itemId);
        }

        public static MenuNode GetByCondition(ISession session, string menuName)
        {
            ICriteria c = session.CreateCriteria(typeof(MenuNode));
            c.Add(Expression.Eq("menuName", menuName));
            return c.UniqueResult<MenuNode>();
        }

        public static IList<MenuNode> GetAll(ISession session)
        {
            ICriteria c = session.CreateCriteria(typeof(MenuNode));
            c.AddOrder(Order.Desc("menuOrderNumber"));
            return c.List<MenuNode>();
        }

        public static IList<MenuNode> GetAllByCondition(ISession session)
        {
            ICriteria c = session.CreateCriteria(typeof(MenuNode));
            c.AddOrder(Order.Desc("menuOrderNumber"));
            return c.List<MenuNode>();
        }
    }
}
